package com.dao.Impl;

import com.dao.OrderDao;
import com.dao.OrderinfoDao;
import com.entity.Order;
import com.entity.Orderinfo;
import com.util.JDBC;
import com.util.TransBean;

import java.util.List;
import java.util.Map;

/**
 * @author 沐白
 */
public class OrderinfoDaoImpl implements OrderinfoDao{
    @Override
    public int add(Orderinfo orderinfo) {
        return JDBC.sqlInsert("insert into orderinfo(orderId,goodsId,goodsNumber,goodsPrice,goodsCredit)" +
                " values(?,?,?,?,?)",orderinfo.getOrderId(),orderinfo.getGoodsId(),orderinfo.getGoodsNumber(),
                orderinfo.getGoodsPrice(),orderinfo.getGoodsCredit());
    }

    @Override
    public List<Orderinfo> findByOrderId(int orderId) {
        List<Map> maps = JDBC.selectMap("select id,orderId,goodsId,goodsNumber,goodsPrice,goodsCredit from orderinfo where\n" +
                " orderId=?", orderId);
        if(maps!=null&&maps.size()>0){
            return TransBean.populate(Orderinfo.class,maps);
        }
        return null;
    }

}
